﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminFunction.Master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="BitPortal.Admin.Note.Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .attachlink
        {
            text-decoration: none;
            line-height: 18px;
        }
        .attachlink img
        {
            margin: 0 1px -6px 0;
        }
    </style>
    <script type="text/javascript">

        var LoadAttachs = function (value) {
            var template = "";
            var arr = value.split("#");
            for (var i = 0; i < arr.length; i++) {
                if (arr[i].length > 0) {
                    var name = arr[i].substring(arr[i].lastIndexOf('/') + 1);
                    template += '<a class="attachlink" href="' + arr[i] + '" target="_blank" title="' + name + '" ><img src="/Images/rar_32.png" width="16" alt="' + name + '" />' + name + '</a><br/>';
                }
            }
            return template;
        };
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="TopBarHolder" runat="server">
    <ext:ButtonGroup ID="ButtonGroup1" runat="server" Layout="ToolbarLayout">
        <Items>
            <ext:Button runat="server" ID="btnAdd" Text="Thêm ghi chú" Icon="NoteAdd" Scale="Medium"
                CausesValidation="false">
                <DirectEvents>
                    <Click OnEvent="btnAdd_Click">
                        <EventMask ShowMask="true" Msg="Waiting..." MinDelay="500" />
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:ToolbarSeparator />
            <ext:Button runat="server" ID="btnEdit" Text="Sửa ghi chú" Icon="NoteEdit" Scale="Medium"
                CausesValidation="false">
                <DirectEvents>
                    <Click OnEvent="btnEdit_Click">
                        <EventMask ShowMask="true" Msg="Waiting..." MinDelay="500" />
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:ToolbarSeparator />
            <ext:Button runat="server" ID="btnDelete" Text="Xóa ghi chú" Icon="NoteDelete" Scale="Medium">
                <DirectEvents>
                    <Click OnEvent="btnDelete_Click">
                        <EventMask ShowMask="true" Msg="Waiting..." MinDelay="500" />
                    </Click>
                </DirectEvents>
            </ext:Button>
        </Items>
    </ext:ButtonGroup>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    
    <ext:Store ID="Store1" runat="server" OnRefreshData="Store1_RefreshData" RemoteSort="true"
        RemotePaging="true">
        <Proxy>
            <ext:PageProxy />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="NoteID">
                <Fields>
                    <ext:RecordField Name="NoteID" Type="Auto" />
                    <ext:RecordField Name="Subject" Type="String" />
                    <ext:RecordField Name="Content" Type="String" />
                    <ext:RecordField Name="Attachs" Type="String" />
                    <ext:RecordField Name="AllowRolesView" Type="String" />
                    <ext:RecordField Name="IsEnabled" Type="Boolean" />
                    <ext:RecordField Name="Logs_DatetimeCreated" Type="Date" ServerMapping="Logs.DatetimeCreated" />
                    <ext:RecordField Name="Logs_DatetimeEdited" Type="Date" ServerMapping="Logs.DatetimeEdited" />
                    <ext:RecordField Name="Logs_CreatingUser" Type="Date" ServerMapping="Logs.CreatingUser" />
                    <ext:RecordField Name="Logs_EditingUser" Type="Date" ServerMapping="Logs.EditingUser" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <BaseParams>
            <ext:Parameter Name="start" Value="0" Mode="Raw" />
            <ext:Parameter Name="limit" Value="10" Mode="Raw" />
            <ext:Parameter Name="sort" Value="" />
            <ext:Parameter Name="dir" Value="" />
        </BaseParams>
        <SortInfo Field="NoteID" Direction="DESC" />
    </ext:Store>


    <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true" Title="Danh sách Media"
        StoreID="Store1">
        <ColumnModel ID="ColumnModel1" runat="server">
            <Columns>
                <ext:ImageCommandColumn Header="" Align="Center" Width="25" Resizable="false">
                    <Commands>
                        <ext:ImageCommand CommandName="MyCommand" Icon="Note" ToolTip-Text="Xem ghi chú">
                        </ext:ImageCommand>
                    </Commands>
                </ext:ImageCommandColumn>
                <ext:Column Header="Mã" DataIndex="NoteID" Groupable="false" Width="20" Align="Center" />
                <ext:Column Header="Tiêu đề" DataIndex="Subject" Width="300" />
                <ext:Column Header="Đính kèm" DataIndex="Attachs" Width="50">
                    <Renderer Fn="LoadAttachs" />
                </ext:Column>
                <ext:Column Header="Role" DataIndex="AllowRolesView" Width="300" Align="Center" Hidden="true" />
                <ext:Column Header="Hiển thị" DataIndex="IsEnabled" Align="Center" Width="30">
                    <Renderer Handler="return (value) ? 'Có':'Không';" />
                </ext:Column>
                <ext:DateColumn Header="Ngày tạo" DataIndex="Logs_DatetimeCreated" Align="Center"
                    Format="dd-MM-yyyy" Width="40" />
                <ext:DateColumn Header="Ngày cập nhật" DataIndex="Logs_DatetimeEdited" Align="Center"
                    Format="dd-MM-yyyy" Width="40" Hidden="true" />
            </Columns>
        </ColumnModel>
        <Listeners>
            <Command Handler="Ext.net.DirectMethods.LoadDetail(record.data.NoteID);" />
        </Listeners>
        <SelectionModel>
            <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" />
        </SelectionModel>
        <View>
            <ext:GroupingView ID="GroupingView1" runat="server" ForceFit="true" MarkDirty="false"
                ShowGroupName="true" EnableNoGroups="true" HideGroupedColumn="true" ShowGroupsText="Nhóm lại theo cột này" />
        </View>
        <LoadMask ShowMask="true" />
        <Plugins>
            <ext:GridFilters runat="server" ID="GridFilters1">
                <Filters>
                    <ext:NumericFilter DataIndex="NoteID" />
                    <ext:StringFilter DataIndex="Subject" />
                    <ext:DateFilter DataIndex="Logs_DatetimeCreated">
                        <DatePickerOptions runat="server" TodayText="Now" />
                    </ext:DateFilter>
                    <ext:DateFilter DataIndex="Logs_DatetimeEdited">
                        <DatePickerOptions runat="server" TodayText="Now" />
                    </ext:DateFilter>
                    <ext:BooleanFilter DataIndex="IsEnabled" />
                </Filters>
            </ext:GridFilters>
            <ext:RowExpander ID="RowExpander1" runat="server">
                <Template ID="Template1" runat="server">
                    <Html>
                        <div style="padding: 8px 20px; line-height: 1.5em; font-size: 12px; font-family: Tahoma">
                        <p><b>Nội dung ghi chú : </b></p>{Content}
                        </div>
                    </Html>
                </Template>
            </ext:RowExpander>
        </Plugins>
        <BottomBar>
            <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="10" />
        </BottomBar>
    </ext:GridPanel>
    
    <uc:NoteAddEdit ID="NoteAddEdit1" runat="Server" ReloadGrid="GridPanel1"></uc:NoteAddEdit>

    <ext:Window ID="wDetail" runat="server" Collapsible="true" Icon="Note" Title="Detail"
        Width="500" Height="200" AutoScroll="true" Hidden="true" ButtonAlign="Center"
        Layout="FormLayout" Padding="10" LabelWidth="200">
        <Content>
            <ext:Label runat="server" ID="lblDatetimeCreate" FieldLabel="Ngày tạo" />
            <ext:Label runat="server" ID="lblDatetimeEdit" FieldLabel="Ngày cập nhật cuối cùng" />
            <ext:Label runat="server" ID="lblCreatingUser" FieldLabel="Người tạo" />
            <ext:Label runat="server" ID="lblEditingUser" FieldLabel="Người sửa cuối cùng" />
            <ext:Label runat="server" ID="lblPermission" FieldLabel="Bạn được quyền" />
        </Content>
        <Buttons>
            <ext:Button ID="btnCancel" runat="server" Text="Đóng lại">
                <Listeners>
                    <Click Handler="#{wDetail}.hide()" />
                </Listeners>
            </ext:Button>
        </Buttons>
    </ext:Window>
</asp:Content>
